package main;

import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import javax.swing.ImageIcon;
import javax.swing.UIManager;

import main.database.Database;
import main.database.DatabaseTuner;
import main.parsers.XmlPath;
import main.parsers.players.Player;
import main.parsers.players.PlayerParser;
import main.ui.LoadingSplash;
import main.ui.MainFrame;

public class Application 
{	  
	public static void main(String[] args) throws NoSuchAlgorithmException 
	{
		try 
		{
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		}
		catch(Exception e) 
		{
			System.out.println("Error");
			e.printStackTrace();
		}
		
		final LoadingSplash splash = new LoadingSplash();
		
		new Thread() 
		{
			public void run()
			{
				splash.setVisible(true);
			}
		}.start();
		
		try 
		{
			DatabaseTuner tuner = DatabaseTuner.load("database.xml");
			Database.getInstance().initialize(tuner);
			XmlPath.getInstance().initialize("xpath.xml");
			Runtime.getRuntime().addShutdownHook(new Thread() 
			{
				public void run() 
				{
					Database.getInstance().release();
				}
			});
			//PlayerParser.getInstance().parse("13041");
			//PlayerParser.getInstance().updatePlayers();

			MainFrame.getInstance().createContent();
			MainFrame.getInstance().setVisible(true);
		} 
		catch (Exception e) 
		{
			System.out.println("Error");
			e.printStackTrace();
		}
		finally 
		{
			splash.setVisible(false);
		}


	}

}
